package com.we823.project.repository.dao.repo;

import java.util.List;
import java.util.Set;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.we823.project.model.repo.MaterialStockOutModel;

@Repository("materialStockOutRepository")
public interface MaterialStockOutRepository extends JpaRepository<MaterialStockOutModel, Integer> {

	List<MaterialStockOutModel> findByIdIn(List<Integer> stockOutIdList);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1")
	Page<MaterialStockOutModel> findByEdittime(int year, Pageable pageable);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and month(m.edittime)=?2")
	Page<MaterialStockOutModel> findByEdittime(int year, int month,
			Pageable pageable);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and month(m.edittime)=?2 and day(m.edittime)=?3")
	Page<MaterialStockOutModel> findByEdittime(int year, int month, int day,
			Pageable pageable);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1")
	List<MaterialStockOutModel> findByEdittime(int year);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and month(m.edittime)=?2")
	List<MaterialStockOutModel> findByEdittime(int year, int month);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and month(m.edittime)=?2 and day(m.edittime)=?3")
	List<MaterialStockOutModel> findByEdittime(int year, int month, int day);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and m.userId in(?2)")
	Page<MaterialStockOutModel> findByEdittimeAndUserid(int year,
			Set<Integer> userIds, Pageable pageable);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and month(m.edittime)=?2 and m.userId in(?3)")
	Page<MaterialStockOutModel> findByEdittimeAndUserid(int year, int month,
			Set<Integer> userIds, Pageable pageable);

	@Query("select m from MaterialStockOutModel m where year(m.edittime)=?1 and month(m.edittime)=?2 and day(m.edittime)=?3 and m.userId in(?4)")
	Page<MaterialStockOutModel> findByEdittimeAndUserid(int year, int month,
			int day, Set<Integer> userIds, Pageable pageable);

	List<MaterialStockOutModel> findByFlag(int flag);

}
